<?php
namespace app\admin\controller;

use cmf\controller\AdminBaseController;
use think\Validate;
use think\Db;
use app\admin\model\DoctorModel;
use app\admin\model\HospitalDepartModel;
use app\admin\model\HospitalDepartalModel;
use app\admin\model\HospitalListModel;
class DoctorController extends AdminBaseController
{
	 public function index()
     {
    	  return $this->fetch();
     }
      public function doctorlist()
     {
        $levelinfo=Db::name('doctor_list')->select()->toArray();
    	     return $this->fetch('Doctor/list',[
            'listinfo'=>$levelinfo
        ]);
     }
     public function doctorlistedit()
     {
         $data = $this->request->param();
         $partmentinfo=Db::name('hospital_department')->select()->toArray();//部门
         $hospital=Db::name('hospital_list')->select()->toArray();//医院列表
         $departinfo=Db::name('hospital_departmental')->select()->toArray();//科室
         $res=DoctorModel::where('id',$data['id'])->find()->toArray();
         return $this->fetch('Doctor/listedit',[
                'res'=>$res,'partmentinfo'=>$partmentinfo,'departinfo'=>$departinfo,'hospital'=>$hospital
            ]);
     }
     public function doctorlisteditt()
     {
         $data = $this->request->param();
         $time = time();
         $level=new DoctorModel();
         $add=$level->where('id',$data['id'])->update(['creat_time'=>$time,'name'=>$data['name'],'phone'=>$data['phone'],'idcard'=>$data['idcard'],'hospital'=>$data['hospital'],'department'=>$data['partmentinfo'],'departmental'=>$data['departinfo'],'position'=>$data['position'],'qualifications'=>$data['qualifications'],'status'=>$data['status']]);
         if($add == 1)
          {
            $this->success('修改成功');
          }else{
            $this->error('修改失败');
          }
     }
     public function doctorlistdelete()
     {
         $data = $this->request->param();
         $res=DoctorModel::destroy($data['id']);
         if($res ==1){
                $this->success('删除成功');
            }else{
                $this->error('添加失败');
            }

     }
        //医院筛选
     public function screen()
    {
        $data = $this->request->param();
        if($data['keyword'] != "")
        {

            $map['name'] = array('like', '%' . $data['keyword'] . '%');
            $listinfo=Db::name('doctor_list')->where($map)->select()->toArray();
        }else if($data['category'] !=""){
            $whereArr['agentid'] =  array('neq',0); // 不等于条件
            $listinfo=Db::name('doctor_list')->where('status',$data['category'])->select()->toArray();
            $levelinfo=Db::name('hospital_level')->where($whereArr)->select()->toArray();
        }else{
             $whereArr['agentid'] =  array('neq',0); // 不等于条件
             $listinfo=Db::name('doctor_list')->select()->toArray();
             $levelinfo=Db::name('hospital_level')->where($whereArr)->select()->toArray();
        }
        return $this->fetch('Doctor/list',[
            'listinfo'=>$listinfo
        ]);

    }
}
